<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="title">
            <h2><a href="#" class="back" onclick="history.go(-1)"/>Protocolos</h2>
        </ui:define>

        <ui:define name="body">
            <p:tabView id="tabView">

                <p:tab id="tab1" title="À receber">
                    <h:form id="form">
                        <p:messages id="messagesReceber" closable="true" showDetail="true" autoUpdate="true"/>
                        <p>
                            <p:panel id="protocolosPanel" styleClass="container_24 clearfix">

                                <p:dataTable id="protocolosTable" var="item" value="#{managerProtocoloRecebido.protocolosReceber}" 
                                             styleClass="grid_24" emptyMessage="Nenhum registro"
                                             rowKey="#{item.id}"
                                             selection="#{managerProtocoloRecebido.protocolosSelecionados}">
                                    <f:facet name="header">
                                        Protocolos
                                    </f:facet>

                                    <p:column selectionMode="multiple" style="text-align: center" />

                                    <p:column headerText="Ação" width="50">
                                        <p:commandButton update="@form" title="Receber"
                                                         oncomplete="dlg.show()"
                                                         icon="ui-icon-circle-check" >
                                            <f:setPropertyActionListener target="#{managerProtocoloRecebido.protocoloReceber}" value="#{item}" />
                                        </p:commandButton>
                                    </p:column>

                                    <p:column headerText="Número" style="text-align: center">
                                        #{item.numero}
                                    </p:column>

                                    <p:column headerText="Com data em" style="text-align: center">
                                        <h:outputLabel value="#{item.dataProtocolo}">
                                            <f:convertDateTime pattern="dd/MM/yyyy"  />
                                        </h:outputLabel>
                                    </p:column>

                                    <p:column headerText="Enviado por" style="text-align: center">
                                        #{item.tramites.get(item.tramites.size()-1).transmitente.nome}
                                    </p:column>

                                    <p:column headerText="Da secretaria" style="text-align: center">
                                        #{item.tramites.get(item.tramites.size()-1).secretaria.nome}
                                    </p:column>

                                    <p:column headerText="Em" style="text-align: center">
                                        <h:outputLabel value="#{item.tramites.get(item.tramites.size()-1).dataTransmitente}">
                                            <f:convertDateTime pattern="dd/MM/yyyy"  />
                                        </h:outputLabel>
                                        às
                                        <h:outputLabel value="#{item.tramites.get(item.tramites.size()-1).dataTransmitente}">
                                            <f:convertDateTime pattern="HH:mm:ss"  />
                                        </h:outputLabel>
                                    </p:column>
                                </p:dataTable>

                                <div class="buttonAction">
                                    <p:commandButton id="multiViewButton" value="Receber" 
                                                     styleClass="ui-priority-primary" icon="ui-icon-circle-check"
                                                     update=":tabView:form:protocolosTable, :receberProtocolosLinkPanel"
                                                     actionListener="#{managerProtocoloRecebido.receberTodos()}"/>
                                    <p:button value="Voltar" icon="ui-icon-circle-arrow-w" href="/" />
                                </div>
                            </p:panel>
                        </p>
                        <p:dialog id="modalDialog" header="Confirmação de recebimento" widgetVar="dlg" 
                                  modal="true" draggable="false" appendToBody="true"
                                  height="80" closable="true" resizable="false" >
                            <h:outputText value="Confirmar recebimento do processo ?" />
                            <br/>
                            <div class="buttonAction">
                                <p:commandButton value="Sim" styleClass="ui-priority-primary"
                                                 actionListener="#{managerProtocoloRecebido.recebido()}"
                                                 update="@form" oncomplete="dlg.hide()"
                                                 icon="ui-icon-check"/>
                                <p:commandButton value="Não" icon="ui-icon-close"
                                                 oncomplete="dlg.hide()" />

                            </div>
                        </p:dialog>
                    </h:form>
                </p:tab>

                <p:tab id="tab2" title="Recebidos">
                    <h:form id="protocoloForm" enctype="multipart/form-data">            
                        <p:messages id="messages" closable="true" showDetail="true" autoUpdate="true"  />
                        <p> 
                            <p:panel id="dadosGeraisPanel" styleClass="container_24 clearfix">
                                <h2>Filtros</h2>
                                <br/>

                                <p:outputLabel value="Numero:" styleClass="grid_3" for="numeroInputText" />
                                <p:inputText id="numeroInputText" styleClass="grid_5" 
                                             value="#{managerProtocoloRecebido.protocoloPesquisar.numero}" />

                                <p:outputLabel value="Data:" styleClass="grid_3" for="dataCalendar" />
                                <p:calendar id="dataCalendar" value="#{managerProtocoloRecebido.protocoloPesquisar.dataProtocolo}"
                                            showOn="both" locale="pt" yearRange="1900:2100" 
                                            navigator="true" pattern="dd/MM/yyyy" styleClass="grid_8" />
                                <div class="clear"/>
                                <br/>
                                <div class="buttonAction">
                                    <p:commandButton value="Pesquisar" styleClass="ui-priority-primary"
                                                     actionListener="#{managerProtocoloRecebido.pesquisar()}"
                                                     update=":tabView:protocoloForm"
                                                     id="pesquisarCommandButton" icon="ui-icon-search"/>
                                </div>
                            </p:panel>

                            <p:panel id="protocolosPanel" styleClass="container_24 clearfix">
                                <p:dataTable id="protocolosTable" var="item" value="#{managerProtocoloRecebido.protocolosRecebidos}" 
                                             styleClass="grid_24" emptyMessage="Nenhum registro">  
                                    <f:facet name="header">
                                        Protocolos
                                    </f:facet>

                                    <p:column headerText="Ação" width="50">
                                        <p:button title="Visualizar"
                                                  href="visualizarprotocolo.xhtml?vProtocolo=#{item.id}"
                                                  icon="ui-icon-zoomin"/>
                                    </p:column>

                                    <p:column headerText="Número" style="text-align: center">
                                        #{item.numero}
                                    </p:column>

                                    <p:column headerText="Com data em" style="text-align: center">
                                        <h:outputLabel value="#{item.dataProtocolo}">
                                            <f:convertDateTime pattern="dd/MM/yyyy"  />
                                        </h:outputLabel>
                                    </p:column>

                                    <p:column headerText="Enviado por" style="text-align: center">
                                        #{item.tramites.get(item.tramites.size()-1).transmitente.nome}
                                    </p:column>
                                    
                                    <p:column headerText="Da secretaria" style="text-align: center">
                                        #{item.tramites.get(item.tramites.size()-1).secretaria.nome}
                                    </p:column>

                                    <p:column headerText="Em" style="text-align: center">
                                        <h:outputLabel value="#{item.tramites.get(item.tramites.size()-1).dataTransmitente}">
                                            <f:convertDateTime pattern="dd/MM/yyyy"  />
                                        </h:outputLabel>
                                        às
                                        <h:outputLabel value="#{item.tramites.get(item.tramites.size()-1).dataTransmitente}">
                                            <f:convertDateTime pattern="HH:mm"  />
                                        </h:outputLabel>
                                    </p:column>

                                    <p:column headerText="Recebido em" style="text-align: center">
                                        <h:outputLabel value="#{item.tramites.get(item.tramites.size()-1).dataRecebimento}">
                                            <f:convertDateTime pattern="dd/MM/yyyy"  />
                                        </h:outputLabel>
                                        às
                                        <h:outputLabel value="#{item.tramites.get(item.tramites.size()-1).dataRecebimento}">
                                            <f:convertDateTime pattern="HH:mm"  />
                                        </h:outputLabel>
                                    </p:column>

                                </p:dataTable>

                                <div class="buttonAction">
                                    <p:button value="Cancelar" icon="ui-icon-close"
                                              href="indexprotocolo.xhtml" />
                                </div>

                            </p:panel>
                        </p>
                    </h:form>
                </p:tab>
            </p:tabView>
        </ui:define>
    </ui:composition>
</html>


